package org.cqipc.edu.dao;

import org.apache.ibatis.annotations.*;
import org.cqipc.edu.entity.Goods;

import java.util.List;

/**
 * @Description: 商品数据接口
 * @ClassNmae: GoodsDao
 * @Author: HeYue
 * @DateTime: 2020-11-01 05:21
 **/
public interface GoodsDao {

    @Select("select * from goods")
    List<Goods> queryAll();

    @Select("select * from goods where goods_name = #{goodName}")
    List<Goods> queryByName(String goodName);

    @Select("select * from goods where goods_id = #{goodId}")
    Goods queryById(Integer goodId);

    @Insert("insert into goods values (null,#{goodsName},#{goodsPrice},#{goodsNum},#{type1Id},#{type2Id},#{type3Id}," +
            "#{goodsDesc},#{goodsStatus},#{goodsImage},#{userId})")
    boolean insertGoods(Goods goods);

    @Select("select * from goods where user_id = #{userId} limit #{currentPage},#{limit}")
    List<Goods> queryGoodsByUserAndPage(@Param("currentPage") Integer currentPage, @Param("limit") Integer limit,
                                        @Param("userId") Integer userId);

    @Select("select * from goods where goods_status = 1 limit #{currentPage},#{limit}")
    List<Goods> queryGoodsByUserAndPageToIndex(@Param("currentPage") Integer currentPage, @Param("limit") Integer limit);

    @Select("select * from goods where user_id = #{userId}")
    List<Goods> queryGoodsByUserAll(@Param("userId") Integer userId);


    @Update("<script>" +
            "update goods set goods_status = 1 where goods_id in" +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    boolean batchUpdateGoodsStatus1(List<Integer> list);

    @Update("<script>" +
            "update goods set goods_status = 2 where goods_id in" +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    boolean batchUpdateGoodsStatus2(List<Integer> ids);


    @Delete("<script>" +
            "delete from goods where goods_id in" +
            "<foreach collection='list' item='item' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    boolean batchDelGoods(List<Integer> ids);


    @Select("select * from goods where goods_status = 1")
    List<Goods> getPageCountToiIndex();

    @Select("select * from goods where goods_status = 1 and goods_name like CONCAT('%',#{text},'%') limit " +
            "#{currentPage},#{limit}")
    List<Goods> seacherInfo(@Param("currentPage") Integer currentPage, @Param("limit") Integer limit,
                            @Param("text") String text);

    @Select("select * from goods where goods_status = 1 and goods_name like CONCAT('%',#{text},'%')")
    List<Goods> seacherInfoAll(String text);
}
